package com.botu.springclouddubbocomsumer.controller;
import java.util.concurrent.TimeUnit;
import	java.util.regex.Pattern;

import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.botu.api.DubboService;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: hanzeyao
 * @Date: 2019/12/14 15:36
 * @Description:
 */
@RestController
public class DubboConsumerController {

    @Reference
    private DubboService dubboService;

    @GetMapping(value = "/dubbo/{name}")
    public String hello(@PathVariable String name){
        return dubboService.hello(name);
    }

    @GetMapping(value = "/sayhello/{name}")
    public String sayHello(@PathVariable String name){

        return dubboService.sayHello(name);
    }

    @GetMapping(value = "/demo/{name}")
    @SentinelResource(value = "demo",fallback = "exDeal")
    public String demo(@PathVariable String name){
        return dubboService.sayHello(name);
    }
    public String exDeal(String name,Throwable t){
        return "降级逻辑"+name;
    }

    /**
     * 测试授权
     * @return
     */
    @GetMapping("/authority")
    public String authority(){
        return dubboService.authority();
    }

    /**
     * 测试nacos的权重
     */
    @GetMapping("/weight")
    public String weight(){
        return dubboService.weight();
    }
}
